<template>
  <div class="commission_list-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="margin_right_20">
          用户名称:&nbsp;
          <el-input
            v-model="username"
            @keyup.enter.native="get_commission_list(1)"
            placeholder="请输入内容"
            style="width:100px;height:30px;"
          ></el-input>
        </div>
        <div class="margin_right_20">
          用户ID:&nbsp;
          <el-input
            v-model="userId"
            @keyup.enter.native="get_commission_list(1)"
            placeholder="请输入内容"
            style="width:100px;height:30px;"
          ></el-input>
        </div>
        <div class="margin_right_20">
          账号状态:&nbsp;
          <el-select
            placeholder="请选择"
            @keyup.enter.native="get_commission_list(1)"
            v-model="status1"
          >
            <el-option label="全部" value="0"></el-option>
            <el-option label="启用" value="1"></el-option>
            <el-option label="禁用" value="2"></el-option>
          </el-select>
        </div>
        <div class="btn">
          <el-button type="primary" icon="el-icon-search" @click="get_commission_list(1)">查询</el-button>
        </div>
      </div>
      <div class="table">
        <el-table :data="commissionList" style="width: 100%" height="598">
          <el-table-column prop="name" label="用户昵称"></el-table-column>
          <el-table-column prop="id" label="用户ID"></el-table-column>
          <el-table-column prop="useBalance" label="已使用钻石">
            <template slot-scope="scope">
              <el-button type="text" @click="handledetail(scope.row.id,1)">{{scope.row.useBalance}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="noUseBalance" label="未使用钻石">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="handledetail(scope.row.id,0)"
              >{{scope.row.noUseBalance}}</el-button>
            </template>
          </el-table-column>
          <!-- <el-table-column  label="状态">
              <template slot-scope="scope">
                         <div class="ceil" v-if="scope.row.status == 0">禁用</div>
              <div class="ceil" v-else>启用</div>
              <div class="ceil" >{{scope.row.status==1?'启用':'禁用'}}</div>
             
              </template>
          </el-table-column>-->
          <el-table-column label="钻石账户状态">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="dialogVisible1=true, handlede(scope.row.id)"
                v-if="scope.row.status==1?yxs=true:yxs=false"
              >启用</el-button>
              <el-button
                type="text"
                size="small"
                @click="dialogVisible=true, handlede(scope.row.id)"
                v-else
              >禁用</el-button>
              <!-- <el-button type="text" size="small" @click="handledetail(scope.row.id,scope.row.status)">详情</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>
      </div>
      <el-dialog title="解除禁用" :visible.sync="dialogVisible" width="30%">
        <span>此操作将切换该钻石账户状态为启用,是否继续?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="getProhibit1,dialogVisible=false" style="width:70px;">取 消</el-button>
          <el-button type="primary" @click="getProhibit" style="width:70px;">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog title="禁用" :visible.sync="dialogVisible1" width="30%">
        <span>此操作将切换该钻石账户状态为禁用,是否继续?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible1 = false" style="width:70px;">取 消</el-button>
          <el-button type="primary" @click="getProhibit1" style="width:70px;">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";
import { commission_list } from "../../api/getData";
export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      yxs: true, //控制状态按钮
      userId: "", //用户的Id
      status1: "", //用户状态
      page: 1,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      username: "",
      commissionList: [
        // {id:1,username:'张三',amountCommission:'100',commission1:'20',commission2:'80',status:'1'},
        // {id:2,username:'李四',amountCommission:'100',commission1:'20',commission2:'80',status:'1'},
      ],
      commissionLists: [],
      dialogVisible: false, //修改状态的显示和隐藏
      dialogVisible1: false, //禁用对话框哦
      id: "" //单条数据的id?
    };
  },
  created() {
    if (localStorage.getItem("pageMsg")) {
      var pageMsg = JSON.parse(localStorage.getItem("pageMsg")) || "";
      localStorage.removeItem("pageMsg");
      this.username = pageMsg.username;
      this.currentPage = pageMsg.currentPage;
      this.pageSize = pageMsg.pageSize;
    }
    this.get_commission_list();
  },
  methods: {
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_commission_list();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_commission_list();
    },
    handledetail(id, type) {
      localStorage.setItem("path", JSON.stringify(this.$route.path));

      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          username: this.username
        })
      );
      this.$router.push("/DiamondsDetails?id=" + id + "&type=" + type);
    },
    get_commission_list(currentPage) {
      if (currentPage) {
        this.currentPage = currentPage;
      }
      let data1 =
        "userId=" +
        this.userId +
        "&name=" +
        this.username +
        "&status=" +
        this.status1;
      let data = {
        size: JSON.stringify(this.pageSize),
        current: JSON.stringify(this.currentPage)
      };
      //console.log(data)
      this.$axios.post("web_flow/balance_list?" + data1, data).then(res => {
        this.commissionList = res.data.data.records;
        this.total = res.data.data.total;
        this.page = Math.ceil(this.total / this.pageSize);
        //console.log(res,12)
      });
    },
    //更据条件查询用户列表
    //    async getList(){
    //        let data='userName='+this.username
    //        //console.log(data)
    //        const {data:res}=await this.$axios.post('/web_examine/commission_list',data)
    //        //console.log(res)
    //     },
    //修改用户状态
    getProhibit() {
      this.dialogVisible = false;
      // this.handlede(this.id)
      //console.log(this.id,121)
      let id = "id=" + this.id;
      this.$axios.post("web_user/modify_status", id).then(res => {
        //console.log(res,1211)
        this.status = res.data.status;
        this.get_commission_list();
      });
    },
    //禁用状态下修改用户状态
    getProhibit1() {
      this.dialogVisible1 = false;
      //this.handlede(this.id)
      let id = "id=" + this.id;
      this.$axios.post("web_user/modify_status", id).then(res => {
        //console.log(res,1211)
        this.status = res.data.status;
        this.get_commission_list();
      });
    },
    handlede(id) {
      // let userId=scope.row.userId
      //console.log(id)
      //let extractCommission=1
      let data = "id=" + id;
      this.id = id;
    }
  }
};
</script>


<style lang="less" >
.commission_list-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }
  .content {
    .query {
      .btn {
        .el-button {
          width: 70px;
        }
      }
    }
  }
}
</style>
